# -*- coding: utf-8 -*-#
#-------------------------------------------------------------------------------
# 建立者:        博智科技  
# Name:         demo1764
# Description:  线程函数同步与异步比较
# Author:       yzl
# Date:         2019-03-11
#-------------------------------------------------------------------------------

import gevent
def task(pid):
    gevent.sleep(1)
    print('task %s done'%pid)

def synchronous():  #同步一个线程执行函数
    for i in range(1,10):
        task(i)
def asynchronous(): #异步一个线程执行函数
    threads = [gevent.spawn(task,i) for i in range(10)]
    gevent.joinall(threads)

print('synchronous:')
synchronous()   #同步执行时要等待执行完后再执行
print('asynchronous:')
asynchronous()  #异步时遇到等待则会切换执行

